package com.syq.day2;

import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Stream;


/**
 * this::非静态方法 和 super::非静态方法
 */
public class Sample4 {

    static class Student {
        public String name;
        public int age;

        public Student() {
        }

        public Student(String name, int age) {
            this.name = name;
            this.age = age;
        }

        @Override
        public String toString() {
            return "Student{name='" + name + "', age=" + age + "}";
        }
    }


    static class Util {
        private boolean isMoreThan17(Student student) {
            return student.age > 17;
        }

        boolean isLessThan17(Student student) {
            return student.age < 17;
        }

        /**
         * 过滤学生流中的学生，只打印年龄大于17岁的学生信息
         *
         * @param stream
         */
        void filter(Stream<Student> stream) {
            stream.filter(this::isMoreThan17)
                    .forEach(System.out::println);
        }
    }

    static class ChildUtil extends Util {
        @Override
        void filter(Stream<Student> stream) {
            stream.filter(super::isLessThan17)
                    .forEach(System.out::println);
        }
    }

    public static void main(String[] args) {

//        Util util = new Util();
        Util util = new ChildUtil();
        Stream<Student> stream = Stream.of(
                new Student("syq", 18),
                new Student("syq1", 19),
                new Student("syq2", 16)
        );
        util.filter(stream);
    }

}
